<?php
$this->Html->addCrumb('Coupons');
$this->Html->scriptStart(array('inline' => false));
echo '
      $(function(){
         $(".deleteLink").click(function(event){
          var $link = $(this);
          $.TWS_Overlay("confirm", {title : "Delete confirmation", message : "Are you sure you want to delete this coupon?", buttons : {ok :{onclick : function () { $.TWS_Overlay("hide"); location.href=$link.attr("href");}}}});
          event.preventDefault();
        });

        $(".displayContent").cluetip({splitTitle: "|", cluetipClass: "tws", dropShadow : false, positionBy : "mouse", cursor : "default"});
      });
       ';
$this->Html->scriptEnd();
?>

<h1>Coupons</h1>
<?php echo $this->Session->flash();?>
<?php echo '<div id="actionLink">'.$this->Html->link('Add Coupon', array('controller' => 'Coupons', 'action' => 'add')).'</div>'; ?>
<? if (empty($coupons)) { echo '<p>No Coupons are currently available.</p>'; }
 else {
  ?>
   <table class="results" >
    <thead>
      <tr>
        <th width="14%"><?php echo $this->Paginator->sort('Company.name','Company')?></th>
        <th width="22%"><?php echo $this->Paginator->sort('title','Title')?></th>
        <th width="25%"><?php echo $this->Paginator->sort('description','Description')?></th>
        <th width="8%"><?php echo $this->Paginator->sort('start_date','Start Date')?></th>
        <th width="8%"><?php echo $this->Paginator->sort('end_date','End Date')?></th>
        <th width="8%"><?php echo $this->Paginator->sort('modified','Modified')?></th>
        <th width="15%">Actions</th>
      <tr>
   </thead>
   <tbody>
      <?php foreach ($coupons as $coupon) {
        $rec = $coupon['Coupon'];
        $editLink = $this->Html->link('Edit', array('controller' => 'coupons', 'action' => 'edit', $rec['id']), array("title"=>"Edit this record"));
        $deleteLink = $this->Html->link('Delete', array('controller' => 'coupons', 'action' => 'delete', $rec['id']), array("title"=>"Delete this record", "class"=>'deleteLink'));
        $description = $this->Html->displayPreview(($rec['description']));
        $modified = new DateTime($rec['modified']);
        $start_date = new DateTime($rec['start_date']);
        $end_date = new DateTime($rec['end_date']);
        $imageLink = !empty($rec['image_path']) ? $this->Html->image('camera.png', array('title'=>'Image present', 'class'=>'imageIndicator'))  : "";
        echo '<tr>';
        echo '<td>'.$coupon['Company']['name'].'</td>';
        echo '<td>'.$imageLink.$rec['title'].'</td>';
        echo '<td>'.nl2br($description).'</td>';
        echo '<td>'.$start_date->format('m/d/Y').'</td>';
        echo '<td>'.$end_date->format('m/d/Y').'</td>';
        echo '<td>'.$modified->format('m/d/Y').'</td>';
        echo "<td>$editLink&nbsp;&nbsp;$deleteLink</td>";
        echo '</tr>';
      }?>
   </tbody>
   </table>
  
<?php echo $this->element('pagination'); ?>

 <?php } ?>

